package com.corpdata.app.customer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RequestParam;
import com.corpdata.app.customer.entity.CustomerDoorMap;
import com.corpdata.app.customer.service.CustomerDoorMapService;
import com.corpdata.app.customer.service.CustomerStaffService;
import com.corpdata.common.domain.DataGridRequestDTO;
import com.corpdata.common.result.Result;
import com.corpdata.system.log.WebLog;
import com.corpdata.core.base.BaseController;

/**
 * 会员门禁关联
 * 
 * @author wu
 * @email 64088839@qq.com
 * @date 2018-08-06 15:48:47
 */
 
@Controller
@RequestMapping("app/customerdoorMap")
public class CustomerDoorMapController extends BaseController{

	@Autowired
	private CustomerDoorMapService customerDoorMapService;
	@Autowired
	private CustomerStaffService customerStaffService;
	
	//新增页面
	@GetMapping("/add/{projectId}/{doorId}")
	public String add(ModelMap map,@PathVariable("projectId") String projectId,@PathVariable("doorId") String doorId){
		map.put("doorId", doorId);
		map.put("staffs", customerStaffService.selectByPid(projectId));
		return "app/customer/door/customerDoorMap_add";
	}
	
	//保存数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/save")
	public Result save(CustomerDoorMap record){
		return customerDoorMapService.save(record);
	}
	
	//编辑页面
	@RequestMapping("/edit/{id}/{projectId}")
	public String edit(@PathVariable("id") String id,@PathVariable("projectId") String projectId,ModelMap map){
		map.put("record", customerDoorMapService.findById(id));
		map.put("staffs", customerStaffService.selectByPid(projectId));
		return "app/customer/door/customerDoorMap_edit";
	}
	
	//更新数据
	@WebLog()
	@ResponseBody
	@RequestMapping("/update")
	public Result update(CustomerDoorMap record){
		return customerDoorMapService.update(record);
	}
	
	//删除
	@WebLog()
	@ResponseBody
	@PostMapping("/delete")
	public Result delete(String id){
		return customerDoorMapService.deleteById(id);
	}
	
	//批量删除
	@WebLog()
	@ResponseBody
	@PostMapping("/deletes")
	public Result deletes(@RequestParam("ids[]") String[] ids){
		return customerDoorMapService.deleteByIds(ids);
	}
	
	//详情页面
	@GetMapping("/details/{id}")
	public String details(ModelMap map,@PathVariable("id") String id){
		map.put("record", customerDoorMapService.findById(id));
	    return "app/customer/customerDoorMap_details";
	}
	
	
	//列表数据
	@ResponseBody
	@RequestMapping("/listdata")
	public String findByPage(DataGridRequestDTO dgRequest){
		return customerDoorMapService.findByPage(dgRequest);
	}
	
}
